window.onload = function(){
    getSwiper();
    getNewcontainer();
    getNewdisc();
    getToplist();
    getCenterlist();
    getRightlist();
}

function getSwiper(){
    $ajax({
        url:swiper_url,
        method:'get',
        success:function(e){
            console.log(e);
            if(e.code === 200){   
                let swiper = document.getElementById('swiper-wrapper');
                let data = e.banners;
                let str = '';
                data.forEach(item => {
                    str += `<div class="swiper-slide" style="background-image:url(${item.pic + '?imageView&blur=40x20'}">
                        <div>
                          <img alt="加载失败" src=${item.pic}>
                        </div>
                    </div>`
                })  
                swiper.innerHTML = str;  
                var mySwiper = new Swiper ('.swiper', {
                    loop: true, // 循环模式选项
                    autoplay:true,
                    
                    // // 如果需要分页器
                    pagination: {
                    el: '.swiper-pagination',
                    },
                    
                    // // 如果需要前进后退按钮
                    navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                    },
                    
                    // // 如果需要滚动条
                    // scrollbar: {
                    // el: '.swiper-scrollbar',
                    // },
                })        

            }
        }
    })
}

// 获取热门推荐
function getNewcontainer(){
    $ajax({
        url:recommend,
        method:'get',
        success:function(e){
            if(e.code === 200){
                let data = e.result;
                let getNewcontaine = document.getElementById('getnewcontaine');
                let str = '';
                for(let i=0; i<data.length; i++){
                    str += `<div>
                    <img src="${data[i].picUrl}" alt="加载失败">
                    <a href="#">${data[i].name}</a>
                    <span class="img-back-g"></span>
                    <span class="img-bottom">
                        <span class="bfl"></span>
                        <b>${data[i].type}万</b>
                        <a class="bof"></a>
                    </span>
                </div>`
                }
                getNewcontaine.innerHTML = str;
            }
            console.log(e);
        }
    })
}

// 获取新品上架
function getNewdisc(){
    $ajax({
        url:newdisc,
        method:'get',
        success:function(e){
            console.log(e);
            if(e.code === 200){
                let data = e.products;
            let str = '';
            let platelist = document.getElementById('platelist');
            for(let i=0; i<data.length; i++){
                str += `<li>
                <div class="plate-img-box">
                    <img src="${data[i].coverUrl}" alt="加载失败">
                    <div class="img-back-z"></div>
                    <a href="#" class="plate-img-box-a1">${data[i].albumName}</a>
                    <a href="#" class="plate-img-box-a2">${data[i].artistName}</a>
                </div>
                <a href="#">
                    <div class="action"></div>
                </a>
            </li>`
            }
            platelist.innerHTML = str;
            }
        }
    })
}

function getToplist(){
    $ajax({
        url:toplist,
        method:'get',
        success:function(e){
            if(e.code === 200){
                let data = e.products;
                let str = '';
                let left = document.getElementById('left1');
                for(let i=0; i<data.length; i++){
                    str += `<dd>
                    <span >${i+1}</span>
                    <a href="#">${data[i].albumName}</a>
                    <div class="overflow">
                        <a href="#" class="a1"></a>
                        <a href="#" class="a2"></a>
                        <a href="#" class="a3"></a>
                    </div>
                </dd>`
                }
                left.innerHTML += str + `<dd>
                <span class="qb"><a href="#">查看全部></a></span>
            </dd>`;
            
            }
            console.log(e);
        }
    })
}
function getCenterlist(){
    $ajax({
        url:centerlist,
        method:'get',
        success:function(e){
            if(e.code === 200){
                let data = e.products;
                let str = '';
                let center = document.getElementById('center1');
                for(let i=0; i<data.length; i++){
                    str += `<dd>
                    <span >${i+1}</span>
                    <a href="#">${data[i].albumName}</a>
                    <div class="overflow">
                        <a href="#" class="a1"></a>
                        <a href="#" class="a2"></a>
                        <a href="#" class="a3"></a>
                    </div>
                </dd>`
                }
                center.innerHTML += str + `<dd>
                <span class="qb"><a href="#">查看全部></a></span>
            </dd>`;
            
            }
            console.log(e);
        }
    })
}
function getRightlist(){
    $ajax({
        url:rightlist,
        method:'get',
        success:function(e){
            if(e.code === 200){
                let data = e.products;
                let str = '';
                let right = document.getElementById('right1');
                for(let i=0; i<data.length; i++){
                    str += `<dd>
                    <span >${i+1}</span>
                    <a href="#">${data[i].albumName}</a>
                    <div class="overflow">
                        <a href="#" class="a1"></a>
                        <a href="#" class="a2"></a>
                        <a href="#" class="a3"></a>
                    </div>
                </dd>`
                }
                right.innerHTML += str + `<dd>
                <span class="qb"><a href="#">查看全部></a></span>
            </dd>`;
            
            }
            console.log(e);
        }
    })
}